from PyQt5.QtWidgets import *
from PyQt5 import QtGui
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import pymysql
import io
from PIL.ImageQt import ImageQt,Image
import  base64
import database.admin.setting as setting
import pickle
import PIL
import os
import interface.admin.date_time as date_time
class date_time_window(QMainWindow,date_time.Ui_Form):
    def __init__(self):
        QMainWindow.__init__(self)
        date_time.Ui_Form.__init__(self)
        self.setupUi(self)
        self.begin.setDateTime(QDateTime.currentDateTime())
        self.end.setDateTime(QDateTime.currentDateTime())
        self.begin.setCalendarPopup(True)
        self.end.setCalendarPopup(True)
        self.ok.clicked.connect(self.commit)
        self.cancel.clicked.connect(self.close)
        self.setWindowTitle("设置选课时间")
        self.term.addItem("2018-2019春学期")
        self.term.addItem("2018-2019秋学期")
        self.term.addItem("2019-2020春学期")
        self.term.addItem("2019-2020秋学期")
        self.term.addItem("2020-2021春学期")
        p = QPalette()
        p_ = QPixmap("s000.jpg")
        p_ = p_.scaled(self.width(), self.height())
        p.setBrush(QPalette.Background, QBrush(p_))
        self.setPalette(p)
    def commit(self):
        begin=self.begin.dateTime()
        end=self.end.dateTime()
        now_term=self.term.currentText()
        print(begin,end)
        if(begin<end):
            #os.remove('time.pkl')
            with open('admin/time.pkl', 'wb') as f:
                pickle.dump(begin, f)
                pickle.dump(end, f)
                pickle.dump(now_term,f)
            print(begin,end,now_term)
            QMessageBox.information(self,"提示","修改成功")
        else:
            QMessageBox.critical(self, "错误", "请正确设置时间")
if __name__=='__main__':
    #app=QApplication(sys.argv)
    #md=date_time_window()
    #md.show()
    #sys.exit(app.exec_())
    with open('time.pkl','rb') as f:
        a=pickle.load(f)
        b=pickle.load(f)
        c=pickle.load(f)
    print(a.toString(Qt.ISODate),b.toString(Qt.DefaultLocaleLongDate))
    print(c)